package pers.dawnyang.common.swagger.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * 
 * @author dawn yang
 * 
 */

@Configuration
@ConfigurationProperties("swagger")
@EnableSwagger2
@EnableSwaggerBootstrapUI
@Profile({"local", "dev"})
@ConditionalOnProperty(prefix = "swagger", name = "open", havingValue = "true",
    matchIfMissing = true)
public class SwaggerConfig {

  private String basePackage = "";

  @Bean
  public Docket createRestApi() {
    return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
        .apis(RequestHandlerSelectors.basePackage(basePackage)).paths(PathSelectors.any()).build();
  }

  private ApiInfo apiInfo() {
    return new ApiInfoBuilder().title("使用Swagger2构建简单优雅的API文档").description("推荐RestFul风格")
        .termsOfServiceUrl("www.baidu.com").version("2.0").build();
  }
}
